package com.example.controller;

import com.example.pojo.Result;
import com.example.pojo.baseComponentPojo;
import com.example.pojo.productModelListPojo;
import com.example.service.baseComponentService;
import com.example.service.componentBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName:baseComponentController
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/7/11 14:45
 * @Version 1.0
 */
@RestController
@Slf4j
public class baseComponentController {
    @Autowired
    private baseComponentService baseComponentService;
    @Autowired
    private componentBookService componentBookService;
    @PostMapping("/insertBaseComponent")
    //插入一条新的记录
    public Result insertBaseComponent(@RequestBody baseComponentPojo baseComponent){
        //向基础表中插入数据
        baseComponentService.insertOne(baseComponent);
        //向零部件作业指导书中插入数据：component_book
        //筛选出最新写入的数据,利用的是Id最大筛选
        baseComponentPojo baseComponentPojo=baseComponentService.queryByIdMax();
        //对零部件作业指导书管理中的数据进行修订,依据是baseId
        componentBookService.insertOne(baseComponentPojo);
        return Result.success();
    }
    @PostMapping("/queryAllBaseComponent")
    //查询所有的数据
    public Result queryAllBaseComponent(){
        List<baseComponentPojo> baseComponentPojoList=baseComponentService.queryAll();
        return Result.success(baseComponentPojoList);
    }
    //对零部件信息进行编辑
    @PostMapping("/editBaseComponent")
    public Result editBaseComponent(@RequestBody baseComponentPojo baseComponent){
        //对基础表格信息进行修改
        baseComponentService.editOne(baseComponent);
        componentBookService.editByBaseId(baseComponent);
        return Result.success();
    }
    //辅助函数：对零部件信息进行调用,调用所有的信息
    @PostMapping("/inquiryProductListBaseComponentAll")
    public Result inquiryProductListBaseComponentAll(){
        List<productModelListPojo> pojos=baseComponentService.inquiryProductListBaseComponentAll();
        return Result.success(pojos);
    }
}
